#include "graph.h"
#include <bits/stdc++.h>
#define rep(i,a,b) for (int i = a; i <= b; ++ i)

using namespace std;

int cnt = 0;
int ans[210];
queue< pair<int, int> > coms;

void DFS2(int dep, bool isRoot) {
//	cerr << pos << ' ' << n_roads[pos] << "ATZ.\n";
	if (dep < 0) {
		coms.push(make_pair(LastRoad(), -1));
		Move(LastRoad(), Color());
		return;
	}
	int col = Color();
//	if (col == 2) {
//		coms.push(make_pair(LastRoad(), -1));
//		Move(LastRoad(), col);
//		return;
//	}
//	cerr << "Arr. " << dep << ' ' << pos << ' ' << n_roads[pos] << endl;
	if (col != 2) ++ cnt;
	int deg = NumberOfRoads(), par = LastRoad();
	rep (i,1,deg) if (i != par || isRoot) {
		coms.push(make_pair(i, -1));
		Move(i, 2);
		DFS2(dep - 1, false);
	}
	if (~par && !isRoot) {
		coms.push(make_pair(par, col == 2 ? -1 : col));
		Move(par, 2);
	}
}

void DFS3() {
	while (!coms.empty()) Move(coms.front().first, coms.front().second == -1 ? Color() : coms.front().second), coms.pop();
}

void work() {
	int lst = 1;
	rep (i,1,N) {
		int col = Color();
		cnt = 0;
//		rep (i,1,N) cerr << color[i - 1] << " \n"[i == N];
		DFS2(i, true);
//		cerr << "Doing. " << pos << ' ' << i << ' ' << cnt << ' ' << lst << endl;
		ans[i] += cnt - lst;
		lst = cnt;
		DFS3();
		Move(1, col);
		Move(LastRoad(), Color());
		if (cnt == N) break;
//		rep (i,1,N) cerr << color[i - 1] << " \n"[i == N];
	}
}

void DFS1() {
	int col = Color();
	if (col != 1) {
		Move(LastRoad(), col);
		return;
	}
	int deg = NumberOfRoads(), par = LastRoad();
//	cerr << "From " << par << ' ' << deg << endl;
//	cerr << col << ' ';
	work();
//	cerr << Color() << endl;
//	cerr << "Working." << endl;
	rep (i,1,deg) if (i != par) {
		Move(i, 3);
		DFS1();
	}
	if (~par) Move(par, 3);
}

void Inspect(int R) {
	DFS1();
//	rep (i,1,R) cerr << ans[i] << " \n"[i == R];
	rep (i,1,R) Answer(i, ans[i] / 2);
    // Write your code here.
}

